package milu.servlet;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.transform.Templates;

import milu.util.WebXmlMenu;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

@SuppressWarnings("serial") public class Test extends XslServlet {
	private static Templates templates;

	public void init() {
		templates = xslInit();
	}

	@Override protected Templates getTemplates() {
		return templates;
	}

	@Override protected String getXslFileName() {
		return "test.xsl";
	}

	@Override protected void domGet(HttpServletRequest req, HttpServletResponse resp, Document doc) {
		WebXmlMenu wxm = new WebXmlMenu();
		InputStream is = getServletContext().getResourceAsStream(
				"/WEB-INF/web.xml");
		try {
			List<String> menu = wxm.getMenu(is);
			Element elm = doc.createElement("Menu");
			for (String s : menu) {
				Element elm2 = doc.createElement("Entry");
				elm2.appendChild(doc.createTextNode(s));
				elm.appendChild(elm2);
			}
			doc.getDocumentElement().appendChild(elm);
		} catch (IOException e) {
			log.error(e.getStackTrace());
		}
	}
}
